package com.itcncp.common.util;

//import com.google.zxing.*;
//import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
//import com.google.zxing.client.j2se.MatrixToImageWriter;
//import com.google.zxing.common.BitMatrix;
//import com.google.zxing.common.HybridBinarizer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.UUID;

/**
 * 二维码工具类
 * 
 * @author ShenHuaJie
 * @since 2017年2月21日 下午1:30:29
 */
public class QrcodeUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(RedisUtil.class);

//    public static String createQrcode(String dir, String content) {
//        return createQrcode(dir, content, 300, 300);
//    }

    /**
     * 二维码
     <dependency>
     <groupId>com.google.zxing</groupId>
     <artifactId>core</artifactId>
     <version>${zxing.version}</version>
     </dependency>
     <dependency>
     <groupId>com.google.zxing</groupId>
     <artifactId>javase</artifactId>
     <version>${zxing.version}</version>
     </dependency>
     */

//    public static String createQrcode(String dir, String content, int width, int height) {
//        try {
//            String qrcodeFormat = "png";
//            HashMap<EncodeHintType, String> hints = new HashMap<EncodeHintType, String>();
//            hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
//            BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);
//
//            File file = new File(dir, UUID.randomUUID().toString() + "." + qrcodeFormat);
//            MatrixToImageWriter.writeToPath(bitMatrix, qrcodeFormat, file.toPath());
//            return file.getAbsolutePath();
//        } catch (Exception e) {
//            LOGGER.error("", e);
//        }
//        return "";
//    }
//
//    public static String decodeQr(String filePath) {
//        String retStr = "";
//        if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
//            return "图片路径为空!";
//        }
//        try {
//            BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
//            LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
//            Binarizer binarizer = new HybridBinarizer(source);
//            BinaryBitmap bitmap = new BinaryBitmap(binarizer);
//            HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
//            hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
//            Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
//            retStr = result.getText();
//        } catch (Exception e) {
//            LOGGER.error("", e);
//        }
//        return retStr;
//    }



}
